{% extends "myadmin/base.html" %}

{% block mainbody %}
    <h3>
        商品信息
    </h3>
    <form id="edit-profile" action="{% url 'myadmin_goods_update' goods.id %}" class="form-horizontal" method="post" enctype="multipart/form-data">
        {% csrf_token %}
        <input type="hidden" name="oldpicname" value="{{ goods.picname }}"/>
        <fieldset>
            <legend>添加商品信息</legend>
            <div class="control-group">
                <label class="control-label" for="input01">商品类别：</label>
                <div class="controls">
                    <select name="typeid">
                        {% for vo in typelist %}
                            <option
                                {% if vo.pid == 0 %}
                                    disabled
                                {% endif %}
                                 value="{{ vo.id }}">{{ vo.name }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">商品名称：</label>
                <div class="controls">
                    <input type="text" value="{{ goods.goods }}" name="goods" class="input-xlarge" id="input01"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">生产厂家：</label>
                <div class="controls">
                    <input type="text" name="company" value="{{ goods.company }}" class="input-xlarge" id="input01"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">单价：</label>
                <div class="controls">
                    <input type="text" value="{{ goods.price }}" name="price" class="input-xlarge" id="input01"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">库存量：</label>
                <div class="controls">
                    <input type="text" name="store" class="input-xlarge" id="input01" value="{{ goods.store }}"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">添加时间：</label>
                <div class="controls">
                    <input type="text" disabled name="addtime" value="{{ goods.addtime|date:'Y-m-d H:i:s' }}" class="input-xlarge" id="input01"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">状态：</label>
                <div class="controls">
                    <input type="radio" name="state" class="input-xlarge" id="input01"
                    {% if goods.state == 1 %}
                        checked
                    {% endif %}
                    value="1" /> 新商品
                    <input type="radio" name="state" class="input-xlarge" id="input01"
                    {% if goods.state == 2 %}
                        checked
                    {% endif %}
                    value="2" /> 在售
                    <input type="radio" name="state" class="input-xlarge" id="input01"
                    {% if goods.state == 3 %}
                        checked
                    {% endif %}
                    value="3" /> 已下架
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">商品图片：</label>
                <div class="controls">
                    <input type="file" name="pic" class="input-xlarge" id="input01" onchange="showPreview(this)"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01">商品简介：</label>
                <div class="controls">
                    <script id="editor" name="content" type="text/plain" style="height:500px;">{{ goods.content|safe }}</script>
                </div>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">保存</button> <button type="reset" class="btn">重置</button>
            </div>
            <div class="control-group">
                <label class="control-label" for="input01"></label>
                <div style="width:700px; height:350px;margin-top: 20px;">
                    <img id="portrait" src="/static/goods/{{ goods.picname }}" height="100%"/>
                </div>
            </div>
        </fieldset>
    </form>
    <script type="text/javascript">
        var ue = UE.getEditor('editor');
        SyntaxHighlighter.all();

        <!-- 实时显示打开的图片 -->
        function showPreview(source) {
          var file = source.files[0];
          if(window.FileReader) {
              var fr = new FileReader();
              console.log(fr);
              var portrait = document.getElementById('portrait');
              fr.onloadend = function(e) {
                portrait.src = e.target.result;
              };
              fr.readAsDataURL(file);
              portrait.style.display = 'block';
          }
        }
    </script>
{% endblock %}